<template>
  <div class="app-container">
    <div v-if="device !== 'mobile'">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="发版名称" prop="fbName">
          <el-input
            v-model="queryParams.fbName"
            placeholder="请输入发版名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="发版日期" prop="fbDate">
          <el-date-picker clearable
                          v-model="queryParams.fbDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择发版日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发版类型" prop="fbType">
          <el-select v-model="queryParams.fbType" placeholder="请选择发版类型" clearable>
            <el-option
              v-for="dict in dict.type.yjcz_fb_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['yjcz:fbInfo:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['yjcz:fbInfo:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['yjcz:fbInfo:remove']"
          >删除</el-button>
        </el-col>
<!--        <el-col :span="1.5">-->
<!--          <el-button-->
<!--            type="warning"-->
<!--            plain-->
<!--            icon="el-icon-download"-->
<!--            size="mini"-->
<!--            @click="handleExport"-->
<!--            v-hasPermi="['yjcz:fbInfo:export']"-->
<!--          >导出</el-button>-->
<!--        </el-col>-->
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="fbInfoList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="发版名称" align="center" prop="fbName" />
        <el-table-column label="发版时间" align="center" prop="fbDateTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.fbDateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="发版类型" align="center" prop="fbType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.yjcz_fb_type" :value="scope.row.fbType"/>
          </template>
        </el-table-column>
        <el-table-column label="发版系统" align="center" prop="channelListNames" >
          <template slot-scope="scope">
            <el-tooltip v-if="null != scope.row.channelListNames && scope.row.channelListNames.length > 25" popper-class="my-tooltip" effect="dark" :content="scope.row.channelListNames" placement="top-start">
              <span>{{scope.row.channelListNames.substring(0, 25) + '...'}}</span>
            </el-tooltip>
            <span v-else>
            {{scope.row.channelListNames}}
          </span>
          </template>
        </el-table-column>
        <el-table-column label="带班领导" align="center" prop="fbTeamLeaderName" />
        <el-table-column label="总控" align="center" prop="fbGeneralControlName" show-overflow-tooltip/>
        <el-table-column label="问题收集人" align="center" prop="questionCollectName" show-overflow-tooltip/>
        <el-table-column label="备注" align="center" prop="fbRemark" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="pcEditDutyPerson(scope.row, false)"
              v-hasPermi="['yjcz:fbInfo:editDutyPerson']"
            >维护值班表</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-search"
              @click="pcEditDutyPerson(scope.row, true)"
              v-hasPermi="['yjcz:fbInfo:editDutyPerson']"
            >查看值班表</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleExportDuty(scope.row)"
              v-hasPermi="['yjcz:fbInfo:exportDutyPerson']"
            >导出值班表</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-chat-dot-round"
              @click="createChatGroup(scope.row)"
              v-hasPermi="['yjcz:fbInfo:createChatGroup']"
            >创建值班群</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['yjcz:fbInfo:edit']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['yjcz:fbInfo:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 添加或修改发版版本信息对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-form-item label="发版名称" prop="fbName">
            <el-input v-model="form.fbName" placeholder="请输入发版名称" />
          </el-form-item>
          <el-form-item label="发版时间" prop="fbDateTime">
            <el-date-picker clearable
                            v-model="form.fbDateTime"
                            type="datetime"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            placeholder="请选择发版时间">
            </el-date-picker>
          </el-form-item>
<!--          <el-form-item label="发版时间" prop="fbTime">-->
<!--            <el-time-picker-->
<!--              v-model="form.fbTime"-->
<!--              placeholder="请选择发版时间">-->
<!--            </el-time-picker>-->
<!--          </el-form-item>-->
          <el-form-item label="发版类型" prop="fbType">
            <el-select v-model="form.fbType" placeholder="请选择发版类型">
              <el-option
                v-for="dict in dict.type.yjcz_fb_type"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="发版应用系统" prop="channelListIds">
            <el-select v-model="channelListIds" @change="onChannelChange" filterable multiple placeholder="请选择应用系统" collapse-tags>
              <el-option
                v-for="item in channelList"
                :key="item.pkId"
                :label="item.channelName"
                :value="parseInt(item.pkId)"
              ></el-option>
            </el-select>
            <el-checkbox v-model="checkedAll" style="padding-left: 20px" @change="onCheckedAll">全选</el-checkbox>
          </el-form-item>
          <el-form-item label="带班领导" prop="fbTeamLeader">
            <el-select v-model="form.fbTeamLeader" filterable placeholder="请选择带班领导">
              <el-option
                v-for="item in teamLeaderUserList"
                :key="item.userId"
                :label="item.nickName"
                :value="item.userId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="总控" prop="generalControlIds">
            <el-select v-model="form.generalControlIds" filterable multiple placeholder="请选择总控" collapse-tags>
              <el-option
                v-for="item in userList"
                :key="item.userId"
                :label="item.nickName"
                :value="item.userId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="问题收集人" prop="questionCollectIds">
            <el-select v-model="form.questionCollectIds" filterable multiple placeholder="请选择问题搜集人" collapse-tags>
              <el-option
                v-for="item in userList"
                :key="item.userId"
                :label="item.nickName"
                :value="item.userId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="备注" prop="fbRemark">
            <el-input v-model="form.fbRemark" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
      <pc-duty-person-dialog ref="pcDutyPersonDialog" />
    </div>
    <div v-if="device === 'mobile'">
      <van-form>
        <van-field
          v-model="queryParams.fbName"
          name="发版名称"
          label="发版名称"
          placeholder="发版名称"
        />
        <van-calendar-input
          label="发版日期"
          placeholder="点击选择日期"
          :value="queryParams.fbDate"
          @confirm="onQueryCalConfirm"
          @cancel="onCancelQueryCalendar"
        />
        <van-field-select-picker
          v-model="queryParams.fbType"
          label="发版类型"
          placeholder="点击选择发版类型"
          :columns="dict.type.yjcz_fb_type"
          :option="{label:'label',value:'value'}"
          :isSearch="true"
          @confirm="onConfirmFbType"
        />
        <div style="margin: 16px;">
          <!-- 居中 -->
          <van-row type="flex" justify="center">
            <van-col span="7">
              <van-button style="width: 100%" round type="info" native-type="submit" @click="handleQuery" icon="search">
                搜索
              </van-button>
            </van-col>
            <van-col span="1">
            </van-col>
            <van-col span="7">
              <van-button style="width: 100%" round type="default" @click="resetAndGetList" icon="replay">
                重置
              </van-button>
            </van-col>
            <van-col span="1">
            </van-col>
            <van-col span="7">
              <van-button style="width: 100%" round type="primary" @click="mobileAdd"
                          v-hasPermi="['yjcz:fbInfo:add']" icon="plus">
                新增
              </van-button>
            </van-col>
          </van-row>
        </div>
      </van-form>
<!--      <van-list-->
<!--        v-model="mobilePluginsProp.loading"-->
<!--        :finished="mobilePluginsProp.finished"-->
<!--        finished-text="没有更多了"-->
<!--        @load="mobileGetList"-->
<!--      >-->
      <van-divider>左滑：修改、删除；右滑：维护、查看值班</van-divider>
      <van-collapse v-model="mobilePluginsProp.activeNames">
        <van-swipe-cell v-for="item in fbInfoList">
          <template #left>
            <van-button square type="info" text="查看值班" @click="editDutyPerson(item, 1)" icon="search" />
            <van-button square type="warning" text="维护值班" v-hasPermi="['yjcz:fbInfo:editDutyPerson']" @click="editDutyPerson(item, 0)" icon="records-o" />
<!--            <van-button square type="info" text="导出" @click="handleExportDuty(item)" icon="down" />-->
          </template>
          <van-collapse-item :title="item.fbName + '（' + item.fbDate + '）'" :key="item.pkId">
            <van-cell-group>
              <van-cell :title="'发版名称：' + item.fbName" />
              <van-cell :title="'发版时间：' + (item.fbDateTime ? item.fbDateTime : item.fbDate)" />
              <van-cell :title="'发版类型：' + item.fbTypeName" />
              <van-cell :title="'发版应用系统：' + (null == item.channelListNames ? '无' : item.channelListNames)" />
              <van-cell :title="'带班领导：' + (null == item.fbTeamLeaderName ? '无' : item.fbTeamLeaderName)" />
              <van-cell :title="'总控：' + (null == item.fbGeneralControlName ? '无' : item.fbGeneralControlName)" />
              <van-cell :title="'问题收集人：' + (null == item.questionCollectName ? '无' : item.questionCollectName)" />
              <van-cell :title="'备注：' + (null == item.fbRemark ? '无' : item.fbRemark)" />
            </van-cell-group>
          </van-collapse-item>
          <template #right>
            <van-button square type="primary" text="修改" v-hasPermi="['yjcz:fbInfo:edit']" @click="mobileModify(item)" icon="edit" />
            <van-button square type="danger" text="删除" v-hasPermi="['yjcz:fbInfo:remove']" @click="handleDelete(item)" icon="close" />
          </template>
        </van-swipe-cell>
      </van-collapse>
<!--      </van-list>-->
<!--      <div style="position: fixed; bottom: 0px; width: 100%">-->
        <van-pagination
          v-model="queryParams.pageNum"
          :total-items="total"
          :show-page-size="queryParams.pageSize"
          force-ellipses
          @change="getList"
        />
<!--      </div>-->
      <van-dialog v-model="mobilePluginsProp.showAddOrModDialog" :title="mobilePluginsProp.dialogTitle" :showCancelButton="true" :showConfirmButton="false" style="height: 90%; overflow-y: auto">
          <van-form validate-first @failed="onFailed" @submit="onSubmitMobileForm">
            <!-- 通过 pattern 进行正则校验 -->
            <van-field
              name="发版名称"
              label="发版名称"
              placeholder="发版名称"
              v-model="form.fbName"
              :rules="[{ required: true, message: '请填写发版名称' }, { min: 3, max: 50, message: '长度在 3 到 50 个字符'}]"
            />

            <van-time-picker-input
              @confirm="onConfirmTimePicker"
              :value="form.fbDateTime"
              label="发版时间"
              title="选择发版时间"
              placeholder="点击选择发版时间"
              :rules="[{ required: true, message: '发版时间不能为空'}]"
              />

            <van-field-select-picker
              v-model="form.fbType"
              label="发版类型"
              placeholder="点击选择发版类型"
              :columns="dict.type.yjcz_fb_type"
              :option="{label:'label',value:'value'}"
              :isSearch="true"
              @confirm="onConfirmAddFbType"
              :rules="[{ required: true, message: '发版类型不能为空'}]"
            />


            <van-field-checkbox
              label="发版应用系统"
              placeholder="请选择发版应用系统"
              v-model="form.channelListIds"
              :columns="channelList"
              :option="{label:'channelName',value:'pkId'}"
              @confirm="onChannelSelectConfirm"
              :rules="[{ required: true, message: '发版应用系统不能为空'}]"
              :autosize="true"
            />

            <van-field-select-picker
              v-model="form.fbTeamLeader"
              label="带班领导"
              placeholder="点击选择带班领导"
              :columns="teamLeaderUserList"
              :option="{label:'nickName',value:'userId'}"
              :isSearch="true"
              @confirm="onConfirmAddTeamLeader"
            />

            <van-field-checkbox
              v-model="form.generalControlIds"
              label="总控"
              placeholder="点击选择总控"
              :columns="userList"
              :option="{label:'nickName',value:'userId'}"
              :autosize="true"
            />
            <van-field-checkbox
              v-model="form.questionCollectIds"
              label="问题收集人"
              placeholder="点击选择问题收集人"
              :columns="userList"
              :option="{label:'nickName',value:'userId'}"
              :autosize="true"
            />

            <van-field
              name="备注"
              label="备注"
              autosize
              type="textarea"
              placeholder="备注"
              v-model="form.fbRemark"
            />
            <div style="margin: 16px;">
              <van-button round block type="info" native-type="submit">
                提交
              </van-button>
            </div>
          </van-form>
      </van-dialog>
    </div>
  </div>
</template>

<script>
import {
  listFbInfo,
  getFbInfo,
  delFbInfo,
  addFbInfo,
  updateFbInfo,
  listUser,
  listChannel,
  createChatGroup
} from "@/api/yjcz/fbInfo";
import {mapState} from "vuex";
import {Dialog, Notify} from "vant";
import VanFieldSelectPicker from "@/components/VantTools/VanFieldSelectPicker";
import VanFieldCheckbox from "@/components/VantTools/VanFieldCheckbox";
import VanCalendarInput from "@/components/VantTools/VanCalendarInput";
import VanTimePickerInput from "@/components/VantTools/VanTimePickerInput";
import {parseTime} from "@/utils/ruoyi";
import PcDutyPersonDialog from "@/views/yjcz/dutyPerson/pcDutyPersonDialog";


export default {
  name: "FbInfo",
  dicts: ['yjcz_fb_type'],
  components: {PcDutyPersonDialog, VanTimePickerInput, VanFieldSelectPicker, VanFieldCheckbox, VanCalendarInput },
  computed: {
    ...mapState({
      device: state => state.app.device,
      roleIdMap: state => state.user.allRolesMap
    })
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 发版版本信息表格数据
      fbInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fbName: null,
        fbDate: null,
        fbType: null,
      },
      // 表单参数
      form: {},
      channelListIds: [],
      // 表单校验
      rules: {
        fbName: [
          { required: true, message: "发版名称不能为空", trigger: "blur" },
          { min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur' }
        ],
        fbDateTime: [
          { required: true, message: "发版时间不能为空", trigger: "blur" }
        ],
        // fbTime: [
        //   { required: true, message: "发版时间不能为空", trigger: "blur" }
        // ],
        fbType: [
          { required: true, message: "发版类型不能为空", trigger: "change" }
        ],
        channelListIds: [
          { required: true, message: "发版应用系统不能为空", trigger: "change" }
        ],
      },
      userList: [],
      teamLeaderUserList: [],
      channelList: [],
      checkedAll: false,
      mobilePluginsProp: {
        showCal: false,
        showPicker: false,
        loading: false,
        finished: false,
        activeNames: [],
        showAddOrModDialog: false,
        dialogTitle: '新增版本信息',
        showAddCal: false,
        showAddFbTypePicker: false,
        showAddTeamLeaderPicker: false,
        showAddControlPicker: false
      }
    };
  },
  created() {
    this.getChannelList()
    this.getList();
  },
  methods: {
    /** 查询发版版本信息列表 */
    getList() {
      this.loading = true;
      listFbInfo(this.queryParams).then(response => {
        this.fbInfoList = response.rows;
        if (this.device === 'mobile') {
          this.formatFbTypeForMobile()
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset(true);
    },
    // 表单重置
    reset(resetChannelListIds) {
      this.form = {
        pkId: null,
        fbName: null,
        fbDateTime: null,
        fbType: null,
        fbTeamLeader: null,
        fbTeamLeaderName: null,
        fbGeneralControl: null,
        fbGeneralControlName: null,
        fbRemark: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      if (resetChannelListIds) {
        this.form.channelListIds = null
        this.form = JSON.parse(JSON.stringify(this.form))
        this.checkedAll = false
      }
      this.channelListIds = []
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pkId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset(true);
      this.getUserList()
      // this.getChannelList()
      this.open = true;
      this.title = "添加发版版本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset(true);
      this.getUserList()
      const pkId = row.pkId || this.ids
      getFbInfo(pkId).then(response => {
        this.form = response.data;
        this.channelListIds = this.handleSelectIds(this.form.channelListIds)
        if (this.channelListIds.length === this.channelList.length) {
          this.checkedAll = true
        }
        this.open = true;
        this.title = "修改发版版本信息";
      });
    },
    onChannelChange () {
      this.checkedAll = (this.channelListIds.length === this.channelList.length)
      this.form.channelListIds = this.channelListIds.join(',')
    },
    onCheckedAll () {
      this.channelListIds = (this.checkedAll && this.channelList.length > 0) ? this.channelList.map(item => {return item.pkId}) : []
      this.onChannelChange()
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.channelListIds = this.channelListIds.join(',')
          let fbDateTime = this.form.fbDateTime
          if (fbDateTime) {
            this.form.fbDate = fbDateTime.split(' ')[0]
          }
          if (this.form.pkId != null) {
            updateFbInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFbInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const pkIds = row.pkId || this.ids;
      if (this.device === 'mobile') {
        Dialog.confirm({
          title: '确认删除发版信息',
          message: '是否确认删除发版版本信息？',
        }).then(() => {
          // on confirm
          return delFbInfo(pkIds);
        }).then(() => {
          this.getList()
          Notify({ type: 'success', message: '删除成功' });
        })
        return
      }
      this.$modal.confirm('是否确认删除发版版本信息？').then(function() {
        return delFbInfo(pkIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yjcz/fbInfo/export', {
        ...this.queryParams
      }, `fbInfo_${new Date().getTime()}.xlsx`)
    },
    handleExportDuty (row) {
      this.download('yjcz/fbInfo/exportDutyPerson', {
        ...row
      }, `${row.fbName}_${new Date().getTime()}.xlsx`)
    },
    /** 查询用户列表 */
    getUserList () {
      listUser().then(response => {
        if (response.code === 200) {
          this.userList = response.data
          this.teamLeaderUserList = []
          let teamLeaderRoleId = this.roleIdMap.TEAM_LEADER_ROLE_ID
          this.userList.forEach(item => {
            let roleIdsStr = item.roleIdsStr
            let roleIds = roleIdsStr.split(',')
            if (roleIds.includes(teamLeaderRoleId)) {
              this.teamLeaderUserList.push(item)
            }
          })
        }
      })
    },
    getChannelList () {
      listChannel().then(response => {
        if (response.code === 200) {
          this.channelList = response.data
        } else {
          this.$modal.msgError('获取应用系统列表失败')
        }
      })
    },
    onConfirmTimePicker (datetime) {
      this.form.fbDateTime = parseTime(datetime, '{y}-{m}-{d} {h}:{i}:{s}')
    },
    onConfirmFbType (value) {
      this.queryParams.fbType = value.value
    },
    onConfirmAddFbType (value) {
      this.form.fbType = value.value
    },
    onChannelSelectConfirm (value) {
      this.form.channelListIds = value
    },
    onConfirmAddTeamLeader (value) {
      this.form.fbTeamLeader = value.userId
    },
    // onConfirmAddControlLeader (value) {
    //   this.form.fbGeneralControl = value.userId
    // },
    mobileGetList (isResetPage) {
      if (isResetPage) {
        this.queryParams.pageNum = 1;
        this.fbInfoList = []
      }
      this.getFbListCommon(this.fbInfoList)
    },
    getFbListCommon (fbInfoList) {
      this.mobilePluginsProp.loading = true
      listFbInfo(this.queryParams).then(response => {
        const rows = response.rows
        this.formatFbType(rows, fbInfoList)
        this.total = response.total;
        this.mobilePluginsProp.loading = false;
        if (fbInfoList.length === this.total) {
          this.mobilePluginsProp.finished = true
        } else {
          this.queryParams.pageNum ++
        }
      });
    },
    onQueryCalConfirm (date) {
      this.queryParams.fbDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
    },
    onCancelQueryCalendar () {
      this.queryParams.fbDate = ''
    },
    resetAndGetList () {
      Object.assign(this.queryParams, {
        fbName: null,
        fbType: null,
        fbDate: null,
        pageNum: 1
      })
      this.getList()
    },
    formatFbTypeForMobile () {
      if (this.fbInfoList.length > 0) {
        this.fbInfoList.forEach(r => {
          this.formatFbTypeCommon(r)
        })
      }
    },
    formatFbType (rows, fbInfoList) {
      if (rows && rows.length > 0) {
        rows.forEach(r => {
          this.formatFbTypeCommon(r)
          fbInfoList.push(r)
        })
      }
    },
    formatFbTypeCommon (r) {
      const fbTypeDicts = this.dict.type.yjcz_fb_type
      const fbTypeArr = fbTypeDicts.filter(d => d.value == r.fbType)
      if (fbTypeArr && fbTypeArr.length > 0) {
        r.fbTypeName = fbTypeArr[0].label
      }
    },
    mobileAdd () {
      this.reset();
      this.getUserList()
      this.mobilePluginsProp.showAddOrModDialog = true
      this.mobilePluginsProp.dialogTitle = "新增版本信息"
    },
    mobileModify (row) {
      this.reset();
      this.getUserList()
      getFbInfo(row.pkId).then(response => {
        this.form = response.data;
        this.form.channelListIds = this.handleSelectIds(this.form.channelListIds)
        this.mobilePluginsProp.showAddOrModDialog = true
        this.mobilePluginsProp.dialogTitle = "修改版本信息"
      });
    },
    editDutyPerson (row, readOnly) {
      let params = {
        fbId: row.pkId,
        readOnly: readOnly
      }
      let url = `/yjcz/dutyPerson/${readOnly ? 'search' : 'edit'}`
      this.$tab.openPage(`维护${row.fbName}值班人员`, url, params)
    },
    pcEditDutyPerson (row, readOnly) {
      this.$refs.pcDutyPersonDialog.show(row.pkId, row.fbName, readOnly)
    },
    /** 提交按钮 */
    onSubmitMobileForm() {
      if (typeof this.form.channelListIds === 'object') {
        this.form.channelListIds = this.form.channelListIds.join(',')
      }
      let fbDateTime = this.form.fbDateTime
      if (fbDateTime) {
        this.form.fbDate = fbDateTime.split(' ')[0]
      }
      if (this.form.pkId != null) {
        updateFbInfo(this.form).then(response => {
          if (response.code === 200) {
            Notify({ type: 'success', message: '修改成功' });
            this.mobilePluginsProp.showAddOrModDialog = false
            this.getList()
          } else {
            Notify({ type: 'danger', message: response.msg });
          }
        });
      } else {
        addFbInfo(this.form).then(response => {
          if (response.code === 200) {
            Notify({ type: 'success', message: '新增成功' });
            this.mobilePluginsProp.showAddOrModDialog = false
            this.getList()
          } else {
            Notify({ type: 'danger', message: response.msg });
          }
        });
      }
    },
    handleSelectIds (ids) {
      if (!ids) {
        return []
      }
      var idsArr = ids.split(',')
      var newArr = []
      idsArr.forEach(e => {
        newArr.push(Number(e))
      })
      return newArr
    },
    createChatGroup (fbInfo) {
      createChatGroup(fbInfo.pkId).then(res => {
        if (res.code === 200) {
          this.$modal.msgSuccess("群聊创建成功");
        } else {
          this.$modal.msgError(res.msg)
        }
      })
    }
  }
};
</script>
<style scoped>
.btns .filter-time_btn {
  margin-bottom: 20px;
  width: 100%;
}
</style>
<style>
.my-tooltip {
  max-width: 300px;
}
</style>

